/*
 * Copyright (c) 2018. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.beiuu.myfirstandroidapp.Bean;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.beiuu.myfirstandroidapp.R;
import com.beiuu.myfirstandroidapp.SwipeActivity;
import com.beiuu.myfirstandroidapp.WebShowActivity;
import com.squareup.picasso.Picasso;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;




/**
 * Created by Administrator on 2018/2/24.
 */

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.ViewHolder> {

    private List<News> mList;
    private Context context;


    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView _Image;
        TextView _title;
        View _Row;

        public ViewHolder(View view){
            super(view);
            _Row = view;
            _title = (TextView) view.findViewById(R.id.news_title);
            _Image = (ImageView) view.findViewById(R.id.news_image);
        }
    }



    public NewsAdapter(Context context, List<News> _List){
        this.context = context;
        this.mList = _List;
    }



    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.news_item,parent,false);

        final ViewHolder holder = new ViewHolder(view);

        holder._Row.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int position = holder.getAdapterPosition();
                News newinfo = mList.get(position);

                Intent webIntent = new Intent(context, WebShowActivity.class);
                webIntent.putExtra("NEWINFO" , newinfo );
                context.startActivity(webIntent);

//                Intent swipe = new Intent(context, SwipeActivity.class);
//                context.startActivity(swipe);

            }
        });


        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        News one = mList.get(position);

        holder._title.setText(one.getTitle());

        Picasso .with(context)
                .load(one.getImage())
                //下载中显示的图片
                //.placeholder(R.mipmap.placeholder)
                //下载失败显示的图片
                .error(R.mipmap.error)
                .into(holder._Image);

        Log.d("kwwl","Picasso=="+one.getImage());
        //holder._Image.setImageResource(R.drawable.man);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }



}

//http://blog.csdn.net/jing__jie/article/details/52315656
